<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['plugins']=pdo_getall('core_plugins',array(),array('name','title'),'name');
if($_RQ['op']=='list'){
	//搜索
	$params=array();
	if(!empty($_RQ['title'])){
		$params['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(!empty($_RQ['plugin'])){
		$params['plugin']=trim($_RQ['plugin']);
		$return['params']['plugin']=$_RQ['plugin'];
	}
	$fields=array('ckey','title','plugin');
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$total='';
	$list=pdo_getslice('core_cache',$params,array($pindex,$psize),$total,$fields);
	if($list){
		foreach($list as &$row){
			if(!$row['core'] || $row['plugin']='core'){
				$row['plugin']='系统';
			}else{
				$row['plugin']=$return['plugins'][$row['plugin']]['title'];
			}
		}
	}
	
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			'0'=>array('op'=>'list','title'=>'缓存列表'),
			'1'=>array('op'=>'all','title'=>'清空所有缓存'),
			'2'=>array('op'=>'urlargs','title'=>'更新页面缓存'),
		),
		'search_one'=>array('add'=>false,'name'=>'title','select'=>true,'select_name'=>'plugin','select_title'=>'请选择插件','options'=>'plugins','option_value'=>'name','option_title'=>'title'),
		'list'=>array('data'=>'list','edit'=>false,'del_message'=>'确认删除吗？','key'=>'ckey','del_op'=>'del','list'=>array(
			'0'=>array('name'=>'title','title'=>'缓存名称','type'=>'string'),
			'1'=>array('name'=>'plugin','title'=>'所属模块','type'=>'string'),
			'2'=>array('name'=>'ckey','title'=>'缓存标识','type'=>'string'),
		)),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op'] == 'del'){
	$ckey=trim($_RQ['ckey']);
	if($ckey){
		pdo_delete('core_cache',array('ckey'=>$ckey));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $ckey){
			pdo_delete('core_cache',array('ckey'=>$ckey));
		}
	}
	exi('删除成功！');
}
if($_RQ['op'] == 'all'){
	pdo_delete('core_cache',array());
	exi('缓存清除成功！','','list');
}
if($_RQ['op'] == 'urlargs'){
	//更新页面缓存
	$update=array('urlargs'=>TIMESTAMP);
	core_setting('cache',$update);
	exi('更新成功！','','list');
}